#pragma once
#include "SerialPortFactory.h"
#include <jni.h>
#include <boost\asio\serial_port.hpp>
#include <boost\shared_array.hpp>
#include <boost\asio\streambuf.hpp>
#include <boost\shared_ptr.hpp>
#include <boost\system\error_code.hpp>

typedef boost::shared_ptr<boost::asio::streambuf> streambuf_ptr;
typedef boost::system::error_code ecode;

int set_output_buffer(JNIEnv* penv, jobject out, boost::asio::streambuf& buf);

void call_trans_handle(JNIEnv *penv, jobject obj, ecode code, jint size);

void call_recv_handle(JNIEnv *penv, jobject obj, ecode code, const signed char* bytes, const size_t size);

void call_recv_handle(JNIEnv *penv, jobject obj, ecode code, const signed char* bytes, const size_t size,
	const size_t index_split);

void throw_serial_exception(JNIEnv* penv, const char* msg);

//warps

void warp_trans_handle(const boost::system::error_code& error, // Result of operation.
	std::size_t bytes_transferred, JavaVM* pjvm, jobject obj, boost::shared_array<jbyte>);

void warp_recv_handle_util(const boost::system::error_code& error, // Result of operation.
	std::size_t bytes_transferred, JavaVM* pjvm, jobject obj, SerialPortInfoPtr pserialInfo, Lock lock);

void warp_recv_handle(const boost::system::error_code& error, // Result of operation.
	std::size_t bytes_transferred, JavaVM* pjvm, jobject obj, SerialPortInfoPtr pserialInfo, Lock lock);
/*void warp_recv_handle(const boost::system::error_code& error, // Result of operation.
	std::size_t bytes_transferred, JavaVM* pjvm, jobject obj,
	streambuf_ptr pstreambuf);*/

void warp_timeout_handle(JavaVM* pjvm, jobject obj, const boost::system::error_code& error);

void call_timeout_handle(JNIEnv *penv, jobject obj, const boost::system::error_code& error);

void copy_from_stream(JNIEnv* penv, jbyteArray src, boost::asio::streambuf& stream,size_t off, size_t len);
